package com.lmf.springboot.web;

import com.lmf.springboot.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class MyController {

    @Autowired
    private User user;

    @RequestMapping("/msg")
    public ModelAndView doSome(){
        ModelAndView mv=new ModelAndView();
        user.setId(21);
        user.setName("李四");
        user.setAge(21);
        mv.addObject("user",user);
        mv.setViewName("message");
        return mv;
    }
    @RequestMapping("/msg2")
    public String doSome2(Model model){
        user.setId(22);
        user.setName("李四");
        user.setAge(22);
        model.addAttribute("user",user);
        return "message";
    }
    @RequestMapping("/url")
    public String doSome3(Model model){
        model.addAttribute("id",18070072);
        model.addAttribute("name","李四");
        model.addAttribute("age",25);
        return "url";
    }
    @RequestMapping("/msg3")
    public ModelAndView doSome4(Integer id,String name,Integer age){
        ModelAndView mv=new ModelAndView();
        user.setId(id);
        user.setName(name);
        user.setAge(age);
        mv.addObject("user",user);
        mv.setViewName("message");
        return mv;
    }
    @RequestMapping("/msg4/{id}/{name}/{age}")
    public ModelAndView doSome5(@PathVariable("id") Integer id,
                          @PathVariable("name") String name,
                          @PathVariable("age") Integer age){
        ModelAndView mv=new ModelAndView();
        user.setId(id);
        user.setName(name);
        user.setAge(age);
        mv.addObject("user",user);
        mv.setViewName("message");
        return mv;
    }
    @RequestMapping("/url2")
    public String doSome6(Model model){
//        model.addAttribute("id",18070072);
//        model.addAttribute("name","李四");
//        model.addAttribute("age",25);
        return "url2";
    }
}
